home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Grafik & Text
/
Alpha
/
Tcl
/
UserCode
/
number.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
3KB
|
124 lines
# FILE: number.tcl
#
# LAST UPDATE: 01/06/93 4:27:56 AM
#
# This file contains the following TCL procedure(s):
#
# number -- Returns Roman or alphabetic equivalent numerals
#
# This proc is useful with electricAlias definitions as follows:
#
# electricAlias def •Text •i "§«set item 1; number \$item i»."
# electricAlias def •Text •ii "§«incr item; number \$item i». "
# electricAlias def •Text •I "§«set item 1; number \$item I»."
# electricAlias def •Text •II "§«incr item; number \$item I». "
# electricAlias def •Text •a "§«set item 1; number \$item a»."
# electricAlias def •Text •aa "§«incr item; number \$item a». "
# electricAlias def •Text •A "§«set item 1; number \$item A»."
# electricAlias def •Text •AA "§«incr item; number \$item A». "
#
# USAGE:
#
# number VALUE STYLE
#
# WHERE:
#
# VALUE = positive whole number 1.. (Roman limited to 9999)
# STYLE = a|alpha|alphabetic|i|roman|A|ALPHA|ALPHABETIC|I|ROMAN
#
# EXAMPLE:
#
# [number 1992 ROMAN] returns "MCMXCII"
#
# To use, simply source this file place it in the a folder with the
# name $HOME:Tcl:Usercode: and invoke it implicitly via the "unknown proc".
#
# SEE ALSO unknown.tcl, electricAlias.tcl
# COPYRIGHT:
#
# Copyright © 1992,1993 by David C. Black
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by David C. Black.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
################################################################################
# AUTHOR
#
# David C. Black
# Internet: black@mpd.tandem.com (preferred)
# GEnie: D.C.Black
# USnail: 6217 John Chisum Lane, Austin, TX 78749
#
################################################################################
# HISTORY
#
# modified who rev reason
# -------- --- --- ------
# 01/06/93 DCB 1.0 Original
proc number {value {style I}} {
if {$value <= 0} {
error "Must be a counting number"
}
if {[string first "." $value] >= 0} {
error "Must be an integral value"
}
case $style {
{a alpha alphabetic A ALPHA ALPHABETIC} {
incr value -1
set result [format "%c" [expr {$value % 26 + 0x41}]]
set value [expr {$value / 26}]
while {$value > 0} {
set digit [expr {$value % 26 + 0x40}]
set value [expr {$value / 26}]
set result [format "%c%s" $digit $result]
}
}
{i roman I ROMAN} {
if {$value > 9999} {
"Roman numeral too big"
}
set rlist {
{"" I II III IV V VI VII VIII IX}
{"" X XX XXX XL L LX LXX LXXX XC}
{"" C CC CCC CD D DC DCC DCCC CM}
{"" M MM MMM MV_ V_ VM_ VMM_ VMMM_ MX_}
}
set result ""
set ten 0
while {$value > 0} {
set digit [lindex [lindex $rlist $ten] [expr {$value % 10}]]
set value [expr {$value / 10}]
incr ten
set result "$digit$result"
}
}
default {
error "Unknown numbering style"
}
}
case $style {
{a alpha alphabetic i roman} {
return [string tolower $result]
}
{A ALPHA ALPHABETIC I ROMAN} {
return $result
}
}
}
#endproc number
################################################################################